#ifndef CO_IMPL_H
#define CO_IMPL_H
/*
 *  Copyright 2021-2025 Michael T. Richter as Half-Baked Software
 *  This program is free software. It comes without any warranty, to the extent
 *  permitted by applicable law. You can redistribute it and/or modify it under
 *  the terms of the Do What The Fuck You Want To Public License, Version 2, as
 *  published by Sam Hocevar. See the file COPYING or http://www.wtfpl.net/ for
 *  more details.
 */
/** @file
 *  @brief CPU library CO component, implementation API
 *
 *  CO needs some functions implemented by a target-specific back-end.  These
 *  are:
 *  - co_halt_impl();
 *  - co_init_impl();
 *  - co_prologue_impl();
 *  - co_yield_impl();
 *
 *  co_impl.c contains the versions of these functions that are
 *  architecture-neutral.  The rest are contained in files that look like:
 *
 *    co_impl_<architecture>_<compiler>.c
 *
 *  Thus, for example, co_impl_arm_thumb_iar.c is the implementation file for
 *  CO targetting the ARM Thumb architecture and the IAR compiler.
 */

#include "co.h"

typedef struct _co_t
{
    bool     static_stack;   // stack_store was passed in
    stack_t  *stack_store;   // actual stack array
    stack_t  *stack_pointer; // top of stack
    stack_t  *stack_canary;  // canary location, NULL if not supported
    void     *stash;         // user-supplied data stash
} co_t_impl;

extern co_t co_active;

void co_halt_impl(void);
void co_init_impl(stack_t **stack_pointer, stack_t **stack_canary, co_function co_cb,
                  stack_t *stack_buffer, size_t stack_buffer_count);
__attribute__((naked)) void co_prologue_impl(void);
__attribute__((naked)) void *co_yield_impl(stack_t **stack_pointer, void *data);

#endif //CO_IMPL_H
